package com.hb.core.filter;


import com.hb.core.context.CurrentAccountHolder;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import java.io.IOException;

/**
 * @description: 清除本地线程变量
 * @projectName: zhb-frame-build
 * @author: zhouhaizhi
 * @createTime: 2021/8/27 16:11
 * @version:1.0
 */
@Slf4j
public class ThreadLocalContextFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.debug("[ThreadLocalContextFilter]初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try {
            filterChain.doFilter(servletRequest,servletResponse);
        }finally {
            CurrentAccountHolder.remove();
        }
    }

    @Override
    public void destroy() {
        log.debug("[ThreadLocalContextFilter]销毁");
    }
}
